package lowijs.XfireClient.packet;

import lowijs.XfDroid.FriendDBAdapter;

public class FriendStatusTextPacket extends Packet {
	public FriendStatusTextPacket(byte[] data) {
		int numSids = fromLowHigh(data[9], data[10]);
		byte[][] sids = new byte[numSids][16];
		int pos = 11;
		
		for (int i = 0; i < numSids; i++) {
			System.arraycopy(data, pos, sids[i], 0, 16);
			pos += 16;
		}
		
		pos += 8; // jump to status texts

		String[] status = new String[numSids];
		for (int i = 0; i < numSids; i++) {
			int textLen = fromLowHigh(data[pos], data[pos + 1]);
			byte[] statustext = new byte[textLen];
			System.arraycopy(data, pos + 2, statustext, 0, textLen);
			
			if (textLen == 0) {
				status[i] = "Online";
			} else {
				status[i] = new String(statustext);
			}

			pos += textLen + 2;
		}

		FriendDBAdapter db = FriendDBAdapter.getInstance(null);
		db.status(sids, status);
	}
}
